﻿@model IList<ProductModel>
@{
    Layout = "~/Views/Shared/_Root.cshtml";

    //title
    Html.AddTitleParts(T("PageTitle.CompareProducts").Text);
}
@using Nop.Core;
@using Nop.Core.Infrastructure;
@using Nop.Web.Framework.UI;
@using Nop.Web.Models.Catalog;
@{
    string columnWidth = "";
    if (Model.Count > 0)
    {
        columnWidth = Math.Round((decimal)(90M / Model.Count), 0).ToString() + "%";
    }


    var specificationAttributes = new List<ProductSpecificationModel>();
    foreach (var product in Model)
    {
        foreach (var attribute in product.SpecificationAttributeModels)
        {
            if (specificationAttributes.Where(sa => sa.SpecificationAttributeId == attribute.SpecificationAttributeId).FirstOrDefault() == null)
            {
                specificationAttributes.Add(attribute);
            }
        }
    }
}
<div class="compare-products">
    <div class="page-title">
        <h1>@T("Products.Compare.Title")</h1>
    </div>
    <div class="clear">
    </div>
    <div class="body">
        @if (Model.Count > 0)
        {
            <a href="@Url.RouteUrl("ClearCompareList")" data-role="button" data-ajax="false">@T("Products.Compare.Clear")</a>

            <br />
            <ul data-role="listview" data-inset="true" data-filter="false">
                @foreach (var product in Model)
                {
                    <li>
                    <div class="item">
                        <div class="remove">
                            <a href="@Url.RouteUrl("RemoveProductFromCompareList", new { productId = product.Id })" class="remove-button" data-role="button" data-ajax="false">@T("Common.Remove")</a>
                        </div>
                        <div class="product-picture">
                            <img alt="@product.DefaultPictureModel.AlternateText" src="@product.DefaultPictureModel.ImageUrl" title="@product.DefaultPictureModel.Title" />
                        </div>
                        <div class="product-name">
                            <a class="link" href="@Url.RouteUrl("Product", new { productId = product.Id, SeName = product.SeName })">@product.Name</a>
                        </div>
                        <div class="productPrice">
                            @T("Products.Compare.Price"): @product.ProductPrice.Price
                        </div>
                        <div class="attributes">
                            @foreach (var specificationAttribute in specificationAttributes)
                            {
                                <div class="attribute">
                                    @specificationAttribute.SpecificationAttributeName:
                                    @{
                                        var foundProductSpec = product.SpecificationAttributeModels.Where(psa => psa.SpecificationAttributeId == specificationAttribute.SpecificationAttributeId).FirstOrDefault();
                                        var specValue = foundProductSpec != null ? foundProductSpec.SpecificationAttributeOption : "";

                                        if (!String.IsNullOrEmpty(specValue))
                                        {
                                        @specValue
                                        }
                                        else
                                        {
                                        <text>&nbsp;</text>
                                        }
                                    }
                                </div>
                            }
                        </div>
                    </div>
                    </li>
                }
            </ul>
        }
    </div>
</div>
